<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/html">
<head>
    <title>账户提现</title>
    <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="/static/css/public.css?v202204271231">
    <link rel="stylesheet" type="text/css" href="/static/qdxwx/css/global.css?v202204271231">
    <link rel="stylesheet" type="text/css" href="/static/qdxwx/css/web.css?v202204271231">
    <link rel="stylesheet" type="text/css" href="/static/qdxwx/css/theme.css?v202204271231">
    <link rel="stylesheet" type="text/css" href="/static/libs/layui-v2.6.8/css/layui.css" />
    <script type="text/javascript" src="/static/libs/jquery/jquery-3.6.0.min.js"></script>
    <script type="text/javascript" src="/static/libs/layui-v2.6.8/layui.js"></script>
</head>
<body>
<div class="pl15 pr15">
    <ul class='l-r-w-Inpt l-r-w-Inpt-tx'>
        <li class="li-one hLh30" style="border-bottom: 1px solid #e2e2e2">
            <tt class="vam fsize14 c-999 f-fM">可提现金额：</tt>
            <tt class="vam fsize14 c-master f-fM">￥
                <#if allowDraw=='ON'>${userAccount.backAmount/100}</#if>
            </tt>
            <a href="javascript:void (0)" onclick="getAllMoney(<#if allowDraw=='ON'>${userAccount.backAmount}</#if>)" title="全部提现" class="f-fM c-red fsize14 fr">
                全部提现
            </a>
        </li>
        <li class="mt20  tac">
            <label class='vam'><b style="color: red;margin-right: 3px">*</b>提现金额：</label>
            <input style="width: 350px" type='text' id='money' name='drawMoney' class='lTxt'>
        </li>
        <li class="mt20  tac">
            <label class='vam'><b style="color: red;margin-right: 3px">*</b>收款人：</label>
            <input style="width: 350px" type='text' id="bankCardName" name='bankCardName' class='lTxt'>
        </li>
        <li class="mt20  tac">
            <label class='vam'><b style="color: red;margin-right: 3px">*</b>银行卡号：</label>
            <input style="width: 350px" type='text' id='bankCardNumber' name='bankCardNumber' class='lTxt'>
        </li>
        <li class="mt20  tac">
            <label class='vam'><b style="color: red;margin-right: 3px">*</b>开户银行：</label>
            <input style="width: 350px" type='text' id='bankName' name='bankName' class='lTxt'>
        </li>
        <#if bankCardList?? && bankCardList?size gt 0>
            <li class='mt20 li-one hLh30'>
                <span class="">
                    <tt class="vam fsize14 c-999 f-fM">历史提现卡号</tt>
                </span>
                <hr>
                <div class="layui-row layui-col-space15 bank-list" id="bank-border">
                    <#list bankCardList as bankCard>
                        <div class="layui-col-xs4 " id="bank-${bankCard.id}" onclick="selectBanks(${bankCard.id})">
                            <div class="bank-item">
                                <p class="fl">${bankCard.bankName!}</p>
                                <p class="fr">收款人：${bankCard.bankCardName!}</p>
                                <h2><span>**** **** ****</span>${bankCard.bankCardNumber?substring(bankCard.bankCardNumber?length-4,bankCard.bankCardNumber?length)}</h2>
                            </div>
                        </div>
                    </#list>
                </div>
            </li>
        </#if>
        <li class='mt30 btn-list tac clear pt15'>
            <label class='vam'>&nbsp;</label>
            <span class='login-btn l-b-small mr20'>
                <input type='button' onclick="withdrawMoney()" value='确 定'>
            </span>
        </li>
    </ul>
</div>
<script type="text/javascript">
    /*全部提现*/
    function getAllMoney(allMoney) {
        console.log(allMoney)
        $("#money").val((allMoney-(allMoney%10000))/100)
    }

    //选择银行卡号
    function selectBanks(id) {
        $.post("/user/account/bank/select.json",{"id":id},function (json) {
            if(json.code === 0){
                $("#bank-border .layui-col-xs4").removeClass("active")
                $("#bank-"+id).addClass("active");
                $("#bankName").val(json.data.bankName)
                $("#bankCardNumber").val(json.data.bankCardNumber)
                $("#bankCardName").val(json.data.bankCardName)
            }else {
                return layer.msg(json.msg);
            }

        })
    }

    /*提现*/
    function withdrawMoney() {
        /*提取金额*/
        var drawMoney = $("#money").val();
        /*提取金额*/
        var bankCardName = $("#bankCardName").val();
        /*银行卡号*/
        var bankCardNumber = $("#bankCardNumber").val();
        /*转账银行*/
        var bankName = $("#bankName").val();
        if (money < 100) {
            return layer.msg("提现金额必须是100的倍数，最低提现100元");
        }
        if (bankCardName == null || bankCardName === "") {
            return layer.msg("请填写收款人名称" );
        }
        if (bankCardNumber == null || bankCardNumber === "") {
            return layer.msg("请填写银行卡号");
        }
        if (bankName == null || bankName === "") {
            return layer.msg("请填写银行卡所属银行");
        }
        $.ajax({
            url: "/user/account/draw.json",
            post: "post",
            data: {
                "drawMoney": drawMoney,
                "bankCardName": bankCardName,
                "bankCardNumber": bankCardNumber,
                "bankName": bankName,
            },
            success: function (result) {
                if (result.code === 0) {
                    return layer.alert("您的提现申请已经提交成功，请等待管理员审核，您可以在用户中心查看进度！", function () {
                        location.href = '/user/account.html';
                    });
                } else {
                    return layer.alert("由于以下原因，提现失败：" + result.msg);
                }
            }
        })
    }
</script>
</body>
</html>